﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VisionDemo.Application.RunModels.Models;

namespace VisionDemo.Application.RunModels.ViewModels
{
    public class RunViewModel : ObservableRecipient
    {

        //public ObservableCollection<LogModel> LogList { get; set; } = new ObservableCollection<LogModel>();
        private string richText;
        public string RichText
        {
            get { return richText; }
            set { SetProperty(ref richText, value); }
        }

        private bool _RunBTFocused;

        public bool RunBTFocused
        {
            get { return _RunBTFocused; }
            set { SetProperty(ref _RunBTFocused, value); }
        }
        private bool _StopEnabled;

        public bool StopEnabled
        {
            get { return _StopEnabled; }
            set { SetProperty(ref _StopEnabled, value); }
        }
        private bool _RunEnabled;

        public bool RunEnabled
        {
            get { return _RunEnabled; }
            set { SetProperty(ref _RunEnabled, value); }
        }
        private string _RunColor;

        public string RunColor
        {
            get { return _RunColor; }
            set { SetProperty(ref _RunColor, value); }
        }
        private string _StopColor;

        public string StopColor
        {
            get { return _StopColor; }
            set { SetProperty(ref _StopColor, value); }
        }
        private bool _ResetEnabled;

        public bool ResetEnabled
        {
            get { return _ResetEnabled; }
            set { SetProperty(ref _ResetEnabled, value); }
        }
        private string _ResetColor;

        public string ResetColor
        {
            get { return _ResetColor; }
            set { SetProperty(ref _ResetColor, value); }
        }
        public RelayCommand RunCommand { get; set; }
        public RelayCommand StopCommand { get; set; }
        public RelayCommand ResetCommand { get; set; }
        public RunViewModel()
        {
            RunEnabled = true;
            StopEnabled = false;
            StopColor = "#888";
            RunColor = "Orange";
            ResetEnabled = true;
            ResetColor = "Orange";
            RunCommand = new RelayCommand(() =>
            {
                RunEnabled = false;
                RunColor = "#888";
                StopEnabled = true;
                StopColor = "Orange";
                ResetEnabled= false;
                ResetColor = "#888";
            });
            StopCommand = new RelayCommand(() =>{
                RunEnabled = true;
                StopEnabled = false;
                StopColor = "#888";
                RunColor = "Orange";
                ResetEnabled = true;
                ResetColor = "Orange";
            });
            ResetCommand = new RelayCommand(() =>
            {

            });
            RunViewLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " " + "456" + "\r\n");
        }
        void RunViewLog(string message)
        {
            Task.Run(() =>
            {
                Thread.Sleep(50);
                RichText = message;
            });
        }
    }
}
